//
//  QYShareViewController.m
//  QYBaseProject
//
//  Created by Dxc_iOS on 2018/7/20.
//  Copyright © 2018年 代星创. All rights reserved.
//

#import "QYShareViewController.h"
#import <LEEAlert.h>
#import "ShareView.h"
#import "AllMoreShareView.h"
#import "ShareSDKManager.h"
#import "Configuration.h"
@interface QYShareViewController ()
    @property (nonatomic,strong)ShareView *shareView;
@end

@implementation QYShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:shareBtn];
    shareBtn.frame = CGRectMake(100,150, 100, 50);
    [shareBtn setTitle:@"分享" forState:UIControlStateNormal];
    shareBtn.backgroundColor = [UIColor blackColor];
    [shareBtn addTarget:self action:@selector(shareBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *shareBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:shareBtn2];
    shareBtn2.frame = CGRectMake(100,250, 100, 50);
    [shareBtn2 setTitle:@"分享2" forState:UIControlStateNormal];
    shareBtn2.backgroundColor = [UIColor blackColor];
    [shareBtn2 addTarget:self action:@selector(shareBtn2Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    /**
     初始化分享视图
     */
    CGFloat width = CGRectGetHeight([[UIScreen mainScreen] bounds]) > CGRectGetWidth([[UIScreen mainScreen] bounds]) ? CGRectGetWidth([[UIScreen mainScreen] bounds]) - 20 : CGRectGetHeight([[UIScreen mainScreen] bounds]) - 20;
    self.shareView = [[ShareView alloc] initWithFrame:CGRectMake(0, 100, width, 250) InfoArray:nil MaxLineNumber:2 MaxSingleCount:3];
      __weak typeof(self)weakSelf = self;
    self.shareView.openShareBlock = ^(ShareType type){
        NSLog(@"%d" , type);
        [weakSelf didselectbutton:type];
    };
    
}
    
#pragma mark - Events

-(void)shareBtn2Clicked{
     AllMoreShareView *view = [[AllMoreShareView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]), 0) ShowMore:YES ShowReport:YES];
    __weak typeof(self)weakSelf = self;
     view.openShareBlock = ^(ShareType type) {
     NSLog(@"%d" , type);
       
    [weakSelf didselectbutton:type];
     };
     view.openMoreBlock = ^(MoreType type) {
     switch (type) {
     case MoreTypeToTheme:
         {// 主题切换
             
         }
     
     break;
     
     case MoreTypeToReport:
         {// 举报
             
         }
             
     
     break;
     
     case MoreTypeToFontSize:
      // 设置字体大小
         {
             
         }
             
     break;
     
     case MoreTypeToCopyLink:
     
     // 复制链接
         {
             
         }
             
     break;
     
     default:
     break;
     }
     
     };
     
     // 显示代码可以封装到自定义视图中 例如 [view show];
     
     [LEEAlert actionsheet].config
     .LeeAddCustomView(^(LEECustomView *custom) {
     custom.view = view;
     custom.isAutoWidth = YES;
     })
     .LeeItemInsets(UIEdgeInsetsMake(0, 0, 0, 0))
     .LeeAddAction(^(LEEAction *action) {
     action.title = @"取消";
     action.titleColor = [UIColor grayColor];
     action.height = 45.0f;
     })
     .LeeHeaderInsets(UIEdgeInsetsMake(0, 0, 0, 0))
     .LeeActionSheetBottomMargin(0.0f)
     .LeeCornerRadius(0.0f)
     .LeeConfigMaxWidth(^CGFloat(LEEScreenOrientationType type) {
     
     return CGRectGetWidth([[UIScreen mainScreen] bounds]);
     })
     .LeeOpenAnimationConfig(^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {
     [UIView animateWithDuration:1.0f delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{
     animatingBlock(); //调用动画中Block
     
     } completion:^(BOOL finished) {
     animatedBlock(); //调用动画结束Block
     }];
     })
     .LeeShow();
     

}
-(void)shareBtnClicked{
    
     
     [LEEAlert actionsheet].config
     .LeeAddCustomView(^(LEECustomView *custom) {
     custom.view = self.shareView;
     custom.positionType = LEECustomViewPositionTypeCenter;
     })
     .LeeItemInsets(UIEdgeInsetsMake(0, 0, 0, 0))
     .LeeAddAction(^(LEEAction *action) {
     action.type = LEEActionTypeDefault;
     action.title = @"取消";
     action.titleColor = [UIColor grayColor];
     })
     .LeeShow();

}
-(void)didselectbutton:(NSInteger)tag
{
    
    switch (tag) {
        case 0://QQ
        {
            [ShareSDKManager shareSDKContentWithImageArrary:@"传入的图片名" title:@"分享标题" content:@"QQ的分享内容" URL:@"http://mob.com" type:3 withSuccess:^(id result) {}];
            break;
        }
        case 1://qq空间
        {
            [ShareSDKManager shareSDKContentWithImageArrary:@"传入的图片名" title:@"分享标题" content:@"分享内容" URL:@"http://mob.com" type:4 withSuccess:^(id result) {}];
            break;
        }
        case 2://微信
        {
            [ShareSDKManager shareSDKContentWithImageArrary:@"传入的图片名" title:@"分享标题" content:@"分享内容" URL:@"http://mob.com" type:0 withSuccess:^(id result) {}];
            break;
        }
        case 3://朋友圈
        {
            [ShareSDKManager shareSDKContentWithImageArrary:@"传入的图片名" title:@"分享标题" content:@"分享内容" URL:@"http://mob.com" type:1 withSuccess:^(id result) {}];
            break;
        }
        case 4://微博
        {
            [ShareSDKManager shareSDKContentWithImageArrary:@"传入的图片名" title:@"分享标题" content:@"分享内容" URL:@"http://mob.com" type:2 withSuccess:^(id result) {}];
            break;
        }
        case 5://复制链接
        {
            
            break;
        }
        default:
            break;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
